﻿using System;
using System.Collections.Generic;

namespace SharpSqlAnalyzer.util
{
	// Token: 0x02000074 RID: 116
	internal class functionListFactory
	{
		// Token: 0x1700003E RID: 62
		// (get) Token: 0x060002CF RID: 719 RVA: 0x002F8626 File Offset: 0x002F6826
		public static functionListFactory Instance
		{
			get
			{
				return functionListFactory.SingletonContainer.instance;
			}
		}

		// Token: 0x060002D0 RID: 720 RVA: 0x002F8630 File Offset: 0x002F6830
		public virtual functionList getBuiltInFunctionList(EDbVendor dbvendor, string dbVersion)
		{
			this.loadBuiltInFunctionList(dbvendor);
			functionMap functionMap = this.functionListMap[dbvendor];
			if (functionMap != null)
			{
				return functionMap.getBuiltInFunctionList(dbVersion);
			}
			return null;
		}

		// Token: 0x060002D1 RID: 721 RVA: 0x002F8660 File Offset: 0x002F6860
		public virtual List<string> getAvailableDbVersions(EDbVendor dbvendor)
		{
			this.loadBuiltInFunctionList(dbvendor);
			functionMap functionMap = this.functionListMap[dbvendor];
			if (functionMap != null)
			{
				return functionMap.DbVersions;
			}
			return null;
		}

		// Token: 0x060002D2 RID: 722 RVA: 0x002F868C File Offset: 0x002F688C
		public virtual bool containsDbVersion(EDbVendor dbvendor, string dbVersion)
		{
			this.loadBuiltInFunctionList(dbvendor);
			functionMap functionMap = this.functionListMap[dbvendor];
			return functionMap != null && dbVersion != null && functionMap.containsVersion(dbVersion);
		}

		// Token: 0x060002D3 RID: 723 RVA: 0x002F86BC File Offset: 0x002F68BC
		protected internal virtual void loadBuiltInFunctionList(EDbVendor dbvendor)
		{
			if (this.functionListMap.ContainsKey(dbvendor))
			{
				return;
			}
			object obj = this.@object;
			lock (obj)
			{
				if (!this.functionListMap.ContainsKey(dbvendor))
				{
					functionMap functionMap = new functionMap();
					this.functionListMap[dbvendor] = functionMap;
					IDictionary<string, string> functionList = functionLoader.getFunctionList(dbvendor);
					if (functionList != null)
					{
						string[] array = new List<string>(functionList.Keys).ToArray();
						List<string> list = new List<string>();
						for (int i = 0; i < array.Length; i++)
						{
							string item = array[i].ToUpper();
							if (!list.Contains(item))
							{
								list.Add(item);
							}
						}
						foreach (string text in list)
						{
							functionList functionList2 = new functionList(dbvendor);
							string key = text;
							if (functionList.ContainsKey(key))
							{
								string[] array2 = functionList[key].Split(new char[]
								{
									','
								});
								for (int j = 0; j < array2.Length; j++)
								{
									string item2 = array2[j].Trim().ToUpper();
									if (!functionList2.BuiltInFunctionList.Contains(item2))
									{
										functionList2.BuiltInFunctionList.Add(item2);
									}
								}
								functionList2.BuiltInFunctionList.Sort();
							}
							functionMap.setBuiltInFunctionList(text, functionList2);
						}
					}
				}
			}
		}

		// Token: 0x060002D4 RID: 724 RVA: 0x002F8864 File Offset: 0x002F6A64
		private functionListFactory()
		{
		}

		// Token: 0x04001082 RID: 4226
		private Dictionary<EDbVendor, functionMap> functionListMap = new Dictionary<EDbVendor, functionMap>();

		// Token: 0x04001083 RID: 4227
		private object @object = new object();

		// Token: 0x02000434 RID: 1076
		private class SingletonContainer
		{
			// Token: 0x04001EC5 RID: 7877
			internal static readonly functionListFactory instance = new functionListFactory();
		}
	}
}
